/**
 * 
 */
package gui.text;

import java.awt.Component;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.util.Arrays;

import javax.swing.Action;
import javax.swing.text.JTextComponent;
import javax.swing.text.TextAction;

/**
 * @author Joshua Lockerman
 *
 */
public class RootMathKit extends MathKit {
    
    private final Action[] actions;
    
    /**
     * 
     */
    public RootMathKit()
    {
        super();
        actions = Arrays.copyOf(super.getActions(), super.getActions().length + 1);
        actions[actions.length - 1] = new TranferFocus("transfer-focus");
    }
    
    
    @Override
    public Action[] getActions()
    {
        return super.getActions();
    }
    
    /**
     * @author Joshua Lockerman
     * 
     */
    public class TranferFocus extends TextAction {
        public TranferFocus(String name)
        {
            super(name);
        }
        
        @Override
        public void actionPerformed(ActionEvent e)
        {
            // TODO Auto-generated method stub
            JTextComponent component = getTextComponent(e);
            Point point = component.getCaret().getMagicCaretPosition();
            Component subcomponent = component.getComponentAt(point);
            if(subcomponent != null) {
                subcomponent.requestFocusInWindow();
            }
        }
    }
}
